<template>
	<view class="content">
		<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption"
			:up="upOption">
			
			<view v-for="(item,index) in list" :key="index"
				 class="items">

			<view class="l">
				<image class="image"
					:src="item.product_avatar"
					mode="widthFix"></image>
				<view class="avatar">
					<view class="name">
							{{item.product_real_name}}
					</view>
					<view class="time">
							{{item.update_time}}
					</view>
				</view>
			</view>
			<view class="r">
				+{{item.income}}({{item.type_text}})
			</view>
			</view>


		</mescroll-body>
	</view>
</template>

<script>
	import imagesUrl from '../../common/images.js'
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				user: null,
				list: [],
				pagination: {
					current:1,
					page: 1,
					pageSize: 0,
					total: 0,
				},
				upOption: {
					page: {
						size: 20 // 每页数据的数量,默认10
					},
					empty: {
						tip: '暂无相关数据'
					},
					textNoMore: "没有更多数据了"
				},
				showCalendarStatus: false,
				startDate: '',
				endDate: '',
				toolTip: "选择日期",
			}
		},
		onLoad() {
			uni.hideLoading()
			this.images = imagesUrl.my
			let that = this;
			this.$u.api.userInfoByToken({}).then(res => {
				that.user = res
				uni.setStorageSync('user_info', JSON.stringify(res))
			})
			uni.$on('updateUserInfo', function(data) {
				this.$u.api.userInfoByToken({}).then(res => {
					that.user = res
					uni.setStorageSync('user_info', JSON.stringify(res))
				})

				this.$u.api.centerConfig({}).then(res => {
					that.navList = res
				})
			})
		},
		onPullDownRefresh() {
			console.log('refresh');
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onReachBottom() {
			console.log('下拉加载')
		},
		created() {

		},
		methods: {
			getList() {
				let that = this;
				let params = {}
				params.page = that.pagination.current;
				params.page_size = 20
				this.$u.api.incomeList(params).then(res => {
					console.log(res)
					if (!res.list) {
						res.list = []
					}
					if (!res.pagination) {
						res.pagination = {}
						res.pagination.total = 0
					}
					that.mescroll.endByPage(res.list.length, res.pagination.total)
					that.pagination.page = that.pagination.current
					if (that.pagination.current*1 == 1) {
						that.list = res.list
					} else {
						that.list = [...that.list, ...res.list]
					}

					that.pagination = res.pagination;
					  that.pagination.current = that.pagination.current*1+1
					that.pagination.page =  that.pagination.current*1+1
				})
			},

			upCallback() {
				this.getList()
			},
			downCallback() {
				this.pagination.page = 1;
				this.pagination.current = 1;
				this.mescroll.resetUpScroll();
			},
			showCalendar() {
				this.showCalendarStatus = true
			},
		}
	}
</script>

<style scoped lang="scss">
	.items {
		padding: 15rpx 30rpx;
		border-bottom: 1px solid #dedede;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	.items .l{
		display: flex;
		align-items: center;
	}
	.items .name{
		font-size: 28rpx;
		color: #333;
	}
	.items .time{
		color: #999;
		font-size: 26rpx;
	}
	.items .r{
		font-size: 28rpx;
		font-weight: bold;
		color: #4892F5;
	}
	.image {
		width: 60rpx;
		height: 60rpx;
		border-radius: 100%;
		margin-right: 20rpx;
	}

	.text {
		display: flex;
		align-items: center;
		font-weight: bold;
		color: #3e8ce1;
		font-size: 28rpx;
	}
</style>
